//
//  StatusListViewModel.swift
//  weibo 666
//
//  Created by mac on 15/11/10.
//  Copyright © 2015年 mac. All rights reserved.
//

import Foundation

class StatusListViewModel {
    
    
    ///微博数据数组
    lazy var statuslist = [StatusViewModel]()
    
    func loadStatus(finished: (isSuccessed: Bool) -> ()){
    
        NetworkTools.sharedTools.loadStatus { (result, error) -> () in
            //判断是否有错误
            if error != nil{
                finished(isSuccessed: false)
                return
            }
            
            //判断数据类型 ----statuses：是一个大的🔢
            guard let array = result?["statuses"] as? [[String: AnyObject]] else {
                print("格式出错了")
                finished(isSuccessed: false)
                return
            }
            //遍历数组字典转模型
            var arrayM = [StatusViewModel]()
            for dict in array{
                arrayM.append(StatusViewModel(status: Status(dict: dict)))
            }
            //拼接数据
            self.statuslist = arrayM + self.statuslist
            
            //完成回调
            finished(isSuccessed: true)
            
        }
    }
}